<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: Super-resolution benchmarking</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d3/d81/tutorial_contrib_root.html">Tutorials for contrib modules</a></li><li class="navelem"><a class="el" href="../../d8/df8/tutorial_table_of_content_dnn_superres.html">Super Resolution using CNNs</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Super-resolution benchmarking </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h2>Benchmarking </h2>
<p>The super-resolution module contains sample codes for benchmarking, in order to compare different models and algorithms. Here is presented a sample code for performing benchmarking, and then a few benchmarking results are collected. It was performed on an Intel i7-9700K CPU on an Ubuntu 18.04.02 OS.</p>
<h2>Source Code of the sample </h2>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">// This file is part of OpenCV project.</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment">// It is subject to the license terms in the LICENSE file found in the top-level directory</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment">// of this distribution and at http://opencv.org/license.html.</span></div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;</div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="preprocessor">#include &lt;opencv2/opencv_modules.hpp&gt;</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;</div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#ifdef HAVE_OPENCV_QUALITY</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="../../d3/db0/dnn__superres_8hpp.html">opencv2/dnn_superres.hpp</a>&gt;</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="../../dd/d5c/quality_8hpp.html">opencv2/quality.hpp</a>&gt;</span></div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="../../d1/d4f/imgproc_2include_2opencv2_2imgproc_8hpp.html">opencv2/imgproc.hpp</a>&gt;</span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="../../d4/dd5/highgui_8hpp.html">opencv2/highgui.hpp</a>&gt;</span></div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;</div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="keyword">using namespace </span>std;</div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="keyword">using namespace </span>dnn_superres;</div><div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;</div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="keyword">static</span> <span class="keywordtype">void</span> showBenchmark(vector&lt;Mat&gt; images, <span class="keywordtype">string</span> title, <a class="code" href="../../d6/d50/classcv_1_1Size__.html">Size</a> imageSize,</div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;                          <span class="keyword">const</span> vector&lt;String&gt; imageTitles,</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;                          <span class="keyword">const</span> vector&lt;double&gt; psnrValues,</div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;                          <span class="keyword">const</span> vector&lt;double&gt; ssimValues)</div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;{</div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;    <span class="keywordtype">int</span> fontFace = <a class="code" href="../../d6/d6e/group__imgproc__draw.html#gga0f9314ea6e35f99bb23f29567fc16e11adfd28fc57520df956e00c7a26fb718ed">FONT_HERSHEY_COMPLEX_SMALL</a>;</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;    <span class="keywordtype">int</span> fontScale = 1;</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;    <a class="code" href="../../d1/da0/classcv_1_1Scalar__.html">Scalar</a> fontColor = <a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(255, 255, 255);</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;</div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;    <span class="keywordtype">int</span> len = <span class="keyword">static_cast&lt;</span><span class="keywordtype">int</span><span class="keyword">&gt;</span>(images.size());</div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;</div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;    <span class="keywordtype">int</span> cols = 2, rows = 2;</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> fullImage = Mat::zeros(<a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>((cols * 10) + imageSize.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a> * cols, (rows * 10) + imageSize.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a> * rows),</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;                               images[0].type());</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;</div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;    stringstream ss;</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;    <span class="keywordtype">int</span> h_ = -1;</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; len; i++) {</div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;        <span class="keywordtype">int</span> fontStart = 15;</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;        <span class="keywordtype">int</span> w_ = i % cols;</div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;        <span class="keywordflow">if</span> (i % cols == 0)</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;            h_++;</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;        <a class="code" href="../../d2/d44/classcv_1_1Rect__.html">Rect</a> ROI((w_ * (10 + imageSize.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>)), (h_ * (10 + imageSize.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>)), imageSize.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>, imageSize.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>);</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;        <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> tmp;</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;        <a class="code" href="../../d5/df1/group__imgproc__hal__functions.html#ga2fe39d2201b12e1b961ca56b2aff9ff2">resize</a>(images[i], tmp, <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(ROI.width, ROI.height));</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;        ss &lt;&lt; imageTitles[i];</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;        <a class="code" href="../../d6/d6e/group__imgproc__draw.html#ga5126f47f883d730f633d74f07456c576">putText</a>(tmp,</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;                ss.str(),</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;                <a class="code" href="../../dc/d84/group__core__basic.html#ga1e83eafb2d26b3c93f09e8338bcab192">Point</a>(5, fontStart),</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;                fontFace,</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;                fontScale,</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;                fontColor,</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;                1,</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;                16);</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;        ss.str(<span class="stringliteral">&quot;&quot;</span>);</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;        fontStart += 20;</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;        ss &lt;&lt; <span class="stringliteral">&quot;PSNR: &quot;</span> &lt;&lt; psnrValues[i];</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;        <a class="code" href="../../d6/d6e/group__imgproc__draw.html#ga5126f47f883d730f633d74f07456c576">putText</a>(tmp,</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;                ss.str(),</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;                <a class="code" href="../../dc/d84/group__core__basic.html#ga1e83eafb2d26b3c93f09e8338bcab192">Point</a>(5, fontStart),</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;                fontFace,</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;                fontScale,</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;                fontColor,</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;                1,</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;                16);</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;        ss.str(<span class="stringliteral">&quot;&quot;</span>);</div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;        fontStart += 20;</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;        ss &lt;&lt; <span class="stringliteral">&quot;SSIM: &quot;</span> &lt;&lt; ssimValues[i];</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;        <a class="code" href="../../d6/d6e/group__imgproc__draw.html#ga5126f47f883d730f633d74f07456c576">putText</a>(tmp,</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;                ss.str(),</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;                <a class="code" href="../../dc/d84/group__core__basic.html#ga1e83eafb2d26b3c93f09e8338bcab192">Point</a>(5, fontStart),</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;                fontFace,</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;                fontScale,</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;                fontColor,</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;                1,</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;                16);</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;        ss.str(<span class="stringliteral">&quot;&quot;</span>);</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;        fontStart += 20;</div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;        tmp.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#a33fd5d125b4c302b0c9aa86980791a77">copyTo</a>(fullImage(ROI));</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;    }</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;</div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;    <a class="code" href="../../d7/dfc/group__highgui.html#ga5afdf8410934fd099df85c75b2e0888b">namedWindow</a>(title, 1);</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;    <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a>(title, fullImage);</div><div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;    <a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>();</div><div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;}</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;<span class="keyword">static</span> <a class="code" href="../../d6/dcf/classcv_1_1Vec.html">Vec2d</a> getQualityValues(<a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> orig, <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> upsampled)</div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;{</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;    <span class="keywordtype">double</span> psnr = <a class="code" href="../../d2/de8/group__core__array.html#ga3119e3ea73010a6f810bb05aa36ac8d6">PSNR</a>(upsampled, orig);</div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;    <a class="code" href="../../d1/da0/classcv_1_1Scalar__.html">Scalar</a> q = quality::QualitySSIM::compute(upsampled, orig, <a class="code" href="../../dc/d84/group__core__basic.html#gad9287b23bba2fed753b36ef561ae7346">noArray</a>());</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;    <span class="keywordtype">double</span> ssim = <a class="code" href="../../d2/de8/group__core__array.html#ga191389f8a0e58180bb13a727782cd461">mean</a>(<a class="code" href="../../dc/d84/group__core__basic.html#ga370d94209693b5b13437ab4991cabf73">Vec3d</a>((q[0]), q[1], q[2]))[0];</div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="../../dc/d84/group__core__basic.html#gaf20d857c2077c986d3b303e3d58bbc54">Vec2d</a>(psnr, ssim);</div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;}</div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;</div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])</div><div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;{</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;    <span class="comment">// Check for valid command line arguments, print usage</span></div><div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;    <span class="comment">// if insufficient arguments were given.</span></div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;    <span class="keywordflow">if</span> (argc &lt; 4) {</div><div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;        cout &lt;&lt; <span class="stringliteral">&quot;usage:   Arg 1: image path  | Path to image&quot;</span> &lt;&lt; endl;</div><div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;        cout &lt;&lt; <span class="stringliteral">&quot;\t Arg 2: algorithm | edsr, espcn, fsrcnn or lapsrn&quot;</span> &lt;&lt; endl;</div><div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;        cout &lt;&lt; <span class="stringliteral">&quot;\t Arg 3: path to model file 2 \n&quot;</span>;</div><div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;        cout &lt;&lt; <span class="stringliteral">&quot;\t Arg 4: scale  | 2, 3, 4 or 8 \n&quot;</span>;</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;        <span class="keywordflow">return</span> -1;</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;    }</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;</div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;    <span class="keywordtype">string</span> path = string(argv[1]);</div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;    <span class="keywordtype">string</span> algorithm = string(argv[2]);</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;    <span class="keywordtype">string</span> model = string(argv[3]);</div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;    <span class="keywordtype">int</span> scale = atoi(argv[4]);</div><div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;</div><div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> img = <a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">imread</a>(path);</div><div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;    <span class="keywordflow">if</span> (img.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abbec3525a852e77998aba034813fded4">empty</a>()) {</div><div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;        cerr &lt;&lt; <span class="stringliteral">&quot;Couldn&#39;t load image: &quot;</span> &lt;&lt; img &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;</div><div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;        <span class="keywordflow">return</span> -2;</div><div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;    }</div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;    <span class="comment">//Crop the image so the images will be aligned</span></div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;    <span class="keywordtype">int</span> width = img.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a> - (img.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a> % <a class="code" href="../../d6/d84/namespacecv_1_1quality_1_1quality__utils.html#ae55d1c89ff5761730174745401162743">scale</a>);</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;    <span class="keywordtype">int</span> height = img.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a> - (img.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a> % <a class="code" href="../../d6/d84/namespacecv_1_1quality_1_1quality__utils.html#ae55d1c89ff5761730174745401162743">scale</a>);</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> cropped = img(<a class="code" href="../../dc/d84/group__core__basic.html#ga11d95de507098e90bad732b9345402e8">Rect</a>(0, 0, width, height));</div><div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;</div><div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;    <span class="comment">//Downscale the image for benchmarking</span></div><div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> img_downscaled;</div><div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;    <a class="code" href="../../d5/df1/group__imgproc__hal__functions.html#ga2fe39d2201b12e1b961ca56b2aff9ff2">resize</a>(cropped, img_downscaled, <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(), 1.0 / scale, 1.0 / scale);</div><div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;</div><div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;    <span class="comment">//Make dnn super resolution instance</span></div><div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;    DnnSuperResImpl sr;</div><div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;</div><div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;    vector &lt;Mat&gt; allImages;</div><div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> img_new;</div><div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;</div><div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;    <span class="comment">//Read and set the dnn model</span></div><div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;    sr.readModel(model);</div><div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;    sr.setModel(algorithm, scale);</div><div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;    sr.upsample(img_downscaled, img_new);</div><div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;</div><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;    vector&lt;double&gt; psnrValues = vector&lt;double&gt;();</div><div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;    vector&lt;double&gt; ssimValues = vector&lt;double&gt;();</div><div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;</div><div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;    <span class="comment">//DL MODEL</span></div><div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;    <a class="code" href="../../d6/dcf/classcv_1_1Vec.html">Vec2f</a> quality = getQualityValues(cropped, img_new);</div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;</div><div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;    psnrValues.push_back(quality[0]);</div><div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;    ssimValues.push_back(quality[1]);</div><div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;</div><div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;    cout &lt;&lt; sr.getAlgorithm() &lt;&lt; <span class="stringliteral">&quot;:&quot;</span> &lt;&lt; endl;</div><div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;    cout &lt;&lt; <span class="stringliteral">&quot;PSNR: &quot;</span> &lt;&lt; quality[0] &lt;&lt; <span class="stringliteral">&quot; SSIM: &quot;</span> &lt;&lt; quality[1] &lt;&lt; endl;</div><div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;    cout &lt;&lt; <span class="stringliteral">&quot;----------------------&quot;</span> &lt;&lt; endl;</div><div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;</div><div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;    <span class="comment">//BICUBIC</span></div><div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> bicubic;</div><div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;    <a class="code" href="../../d5/df1/group__imgproc__hal__functions.html#ga2fe39d2201b12e1b961ca56b2aff9ff2">resize</a>(img_downscaled, bicubic, <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(), scale, scale, <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121a55e404e7fa9684af79fe9827f36a5dc1">INTER_CUBIC</a>);</div><div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;    quality = getQualityValues(cropped, bicubic);</div><div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;</div><div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;    psnrValues.push_back(quality[0]);</div><div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;    ssimValues.push_back(quality[1]);</div><div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;</div><div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;    cout &lt;&lt; <span class="stringliteral">&quot;Bicubic &quot;</span> &lt;&lt; endl;</div><div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;    cout &lt;&lt; <span class="stringliteral">&quot;PSNR: &quot;</span> &lt;&lt; quality[0] &lt;&lt; <span class="stringliteral">&quot; SSIM: &quot;</span> &lt;&lt; quality[1] &lt;&lt; endl;</div><div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;    cout &lt;&lt; <span class="stringliteral">&quot;----------------------&quot;</span> &lt;&lt; endl;</div><div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;</div><div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;    <span class="comment">//NEAREST NEIGHBOR</span></div><div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> nearest;</div><div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;    <a class="code" href="../../d5/df1/group__imgproc__hal__functions.html#ga2fe39d2201b12e1b961ca56b2aff9ff2">resize</a>(img_downscaled, nearest, <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(), scale, scale, <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121aa5521d8e080972c762467c45f3b70e6c">INTER_NEAREST</a>);</div><div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;    quality = getQualityValues(cropped, nearest);</div><div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;</div><div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;    psnrValues.push_back(quality[0]);</div><div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;    ssimValues.push_back(quality[1]);</div><div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;</div><div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;    cout &lt;&lt; <span class="stringliteral">&quot;Nearest neighbor&quot;</span> &lt;&lt; endl;</div><div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;    cout &lt;&lt; <span class="stringliteral">&quot;PSNR: &quot;</span> &lt;&lt; quality[0] &lt;&lt; <span class="stringliteral">&quot; SSIM: &quot;</span> &lt;&lt; quality[1] &lt;&lt; endl;</div><div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;    cout &lt;&lt; <span class="stringliteral">&quot;----------------------&quot;</span> &lt;&lt; endl;</div><div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;</div><div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;    <span class="comment">//LANCZOS</span></div><div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> lanczos;</div><div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;    <a class="code" href="../../d5/df1/group__imgproc__hal__functions.html#ga2fe39d2201b12e1b961ca56b2aff9ff2">resize</a>(img_downscaled, lanczos, <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(), scale, scale, <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121ac6c578caa97f2d00f82bac879cf3c781">INTER_LANCZOS4</a>);</div><div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;    quality = getQualityValues(cropped, lanczos);</div><div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;</div><div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;    psnrValues.push_back(quality[0]);</div><div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;    ssimValues.push_back(quality[1]);</div><div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;</div><div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;    cout &lt;&lt; <span class="stringliteral">&quot;Lanczos&quot;</span> &lt;&lt; endl;</div><div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;    cout &lt;&lt; <span class="stringliteral">&quot;PSNR: &quot;</span> &lt;&lt; quality[0] &lt;&lt; <span class="stringliteral">&quot; SSIM: &quot;</span> &lt;&lt; quality[1] &lt;&lt; endl;</div><div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;    cout &lt;&lt; <span class="stringliteral">&quot;-----------------------------------------------&quot;</span> &lt;&lt; endl;</div><div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;</div><div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;    vector &lt;Mat&gt; imgs{img_new, bicubic, nearest, lanczos};</div><div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;    vector &lt;String&gt; titles{sr.getAlgorithm(), <span class="stringliteral">&quot;Bicubic&quot;</span>, <span class="stringliteral">&quot;Nearest neighbor&quot;</span>, <span class="stringliteral">&quot;Lanczos&quot;</span>};</div><div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;    showBenchmark(imgs, <span class="stringliteral">&quot;Quality benchmark&quot;</span>, <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(bicubic.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a>, bicubic.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a>), titles, psnrValues, ssimValues);</div><div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;</div><div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;    <a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>(0);</div><div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;</div><div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;    <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;}</div><div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;<span class="preprocessor">#else</span></div><div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;<span class="keywordtype">int</span> main()</div><div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;{</div><div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;    std::cout &lt;&lt; <span class="stringliteral">&quot;This sample requires the OpenCV Quality module.&quot;</span> &lt;&lt; std::endl;</div><div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;    <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;}</div><div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;<span class="preprocessor">#endif</span></div><div class="ttc" id="group__core__basic_html_ga599fe92e910c027be274233eccad7beb"><div class="ttname"><a href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">cv::Scalar</a></div><div class="ttdeci">Scalar_&lt; double &gt; Scalar</div><div class="ttdef"><b>Definition:</b> types.hpp:669</div></div>
<div class="ttc" id="group__core__array_html_ga191389f8a0e58180bb13a727782cd461"><div class="ttname"><a href="../../d2/de8/group__core__array.html#ga191389f8a0e58180bb13a727782cd461">cv::mean</a></div><div class="ttdeci">Scalar mean(InputArray src, InputArray mask=noArray())</div><div class="ttdoc">Calculates an average (mean) of array elements. </div></div>
<div class="ttc" id="group__imgproc__transform_html_gga5bb5a1fea74ea38e1a5445ca803ff121a55e404e7fa9684af79fe9827f36a5dc1"><div class="ttname"><a href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121a55e404e7fa9684af79fe9827f36a5dc1">cv::INTER_CUBIC</a></div><div class="ttdef"><b>Definition:</b> imgproc.hpp:251</div></div>
<div class="ttc" id="classcv_1_1Mat_html_abed816466c45234254d25bc59c31245e"><div class="ttname"><a href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">cv::Mat::rows</a></div><div class="ttdeci">int rows</div><div class="ttdoc">the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions ...</div><div class="ttdef"><b>Definition:</b> mat.hpp:2096</div></div>
<div class="ttc" id="classcv_1_1Mat_html_a33fd5d125b4c302b0c9aa86980791a77"><div class="ttname"><a href="../../d3/d63/classcv_1_1Mat.html#a33fd5d125b4c302b0c9aa86980791a77">cv::Mat::copyTo</a></div><div class="ttdeci">void copyTo(OutputArray m) const</div><div class="ttdoc">Copies the matrix to another one. </div></div>
<div class="ttc" id="group__imgcodecs_html_ga288b8b3da0892bd651fce07b3bbd3a56"><div class="ttname"><a href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">cv::imread</a></div><div class="ttdeci">Mat imread(const String &amp;filename, int flags=IMREAD_COLOR)</div><div class="ttdoc">Loads an image from a file. </div></div>
<div class="ttc" id="classcv_1_1Size___html_abfe0367b32c407ddccf5ddf92667c73d"><div class="ttname"><a href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">cv::Size_::width</a></div><div class="ttdeci">_Tp width</div><div class="ttdoc">the width </div><div class="ttdef"><b>Definition:</b> types.hpp:339</div></div>
<div class="ttc" id="highgui_8hpp_html"><div class="ttname"><a href="../../d4/dd5/highgui_8hpp.html">highgui.hpp</a></div></div>
<div class="ttc" id="group__highgui_html_ga453d42fe4cb60e5723281a89973ee563"><div class="ttname"><a href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">cv::imshow</a></div><div class="ttdeci">void imshow(const String &amp;winname, InputArray mat)</div><div class="ttdoc">Displays an image in the specified window. </div></div>
<div class="ttc" id="namespacecv_html"><div class="ttname"><a href="../../d2/d75/namespacecv.html">cv</a></div><div class="ttdoc">&quot;black box&quot; representation of the file storage associated with a file on disk. </div><div class="ttdef"><b>Definition:</b> affine.hpp:51</div></div>
<div class="ttc" id="group__imgproc__draw_html_gga0f9314ea6e35f99bb23f29567fc16e11adfd28fc57520df956e00c7a26fb718ed"><div class="ttname"><a href="../../d6/d6e/group__imgproc__draw.html#gga0f9314ea6e35f99bb23f29567fc16e11adfd28fc57520df956e00c7a26fb718ed">cv::FONT_HERSHEY_COMPLEX_SMALL</a></div><div class="ttdoc">smaller version of FONT_HERSHEY_COMPLEX </div><div class="ttdef"><b>Definition:</b> imgproc.hpp:828</div></div>
<div class="ttc" id="group__core__array_html_ga3119e3ea73010a6f810bb05aa36ac8d6"><div class="ttname"><a href="../../d2/de8/group__core__array.html#ga3119e3ea73010a6f810bb05aa36ac8d6">cv::PSNR</a></div><div class="ttdeci">double PSNR(InputArray src1, InputArray src2, double R=255.)</div><div class="ttdoc">Computes the Peak Signal-to-Noise Ratio (PSNR) image quality metric. </div></div>
<div class="ttc" id="classcv_1_1Size___html"><div class="ttname"><a href="../../d6/d50/classcv_1_1Size__.html">cv::Size_</a></div><div class="ttdoc">Template class for specifying the size of an image or rectangle. </div><div class="ttdef"><b>Definition:</b> types.hpp:315</div></div>
<div class="ttc" id="namespacecv_1_1quality_1_1quality__utils_html_ae55d1c89ff5761730174745401162743"><div class="ttname"><a href="../../d6/d84/namespacecv_1_1quality_1_1quality__utils.html#ae55d1c89ff5761730174745401162743">cv::quality::quality_utils::scale</a></div><div class="ttdeci">void scale(cv::Mat &amp;mat, const cv::Mat &amp;range, const T min, const T max)</div><div class="ttdef"><b>Definition:</b> quality_utils.hpp:90</div></div>
<div class="ttc" id="classcv_1_1Vec_html"><div class="ttname"><a href="../../d6/dcf/classcv_1_1Vec.html">cv::Vec&lt; double, 2 &gt;</a></div></div>
<div class="ttc" id="group__core__basic_html_gad9287b23bba2fed753b36ef561ae7346"><div class="ttname"><a href="../../dc/d84/group__core__basic.html#gad9287b23bba2fed753b36ef561ae7346">cv::noArray</a></div><div class="ttdeci">InputOutputArray noArray()</div></div>
<div class="ttc" id="classcv_1_1Mat_html_aa3e5a47585c9ef6a0842556739155e3e"><div class="ttname"><a href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cv::Mat::cols</a></div><div class="ttdeci">int cols</div><div class="ttdef"><b>Definition:</b> mat.hpp:2096</div></div>
<div class="ttc" id="group__core__basic_html_ga11d95de507098e90bad732b9345402e8"><div class="ttname"><a href="../../dc/d84/group__core__basic.html#ga11d95de507098e90bad732b9345402e8">cv::Rect</a></div><div class="ttdeci">Rect2i Rect</div><div class="ttdef"><b>Definition:</b> types.hpp:462</div></div>
<div class="ttc" id="classcv_1_1Rect___html"><div class="ttname"><a href="../../d2/d44/classcv_1_1Rect__.html">cv::Rect_</a></div><div class="ttdoc">Template class for 2D rectangles. </div><div class="ttdef"><b>Definition:</b> types.hpp:420</div></div>
<div class="ttc" id="group__imgproc__transform_html_gga5bb5a1fea74ea38e1a5445ca803ff121ac6c578caa97f2d00f82bac879cf3c781"><div class="ttname"><a href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121ac6c578caa97f2d00f82bac879cf3c781">cv::INTER_LANCZOS4</a></div><div class="ttdef"><b>Definition:</b> imgproc.hpp:257</div></div>
<div class="ttc" id="quality_8hpp_html"><div class="ttname"><a href="../../dd/d5c/quality_8hpp.html">quality.hpp</a></div></div>
<div class="ttc" id="group__highgui_html_ga5afdf8410934fd099df85c75b2e0888b"><div class="ttname"><a href="../../d7/dfc/group__highgui.html#ga5afdf8410934fd099df85c75b2e0888b">cv::namedWindow</a></div><div class="ttdeci">void namedWindow(const String &amp;winname, int flags=WINDOW_AUTOSIZE)</div><div class="ttdoc">Creates a window. </div></div>
<div class="ttc" id="classcv_1_1Size___html_a1d289dce6b5d8006a54f3ee0259fc545"><div class="ttname"><a href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">cv::Size_::height</a></div><div class="ttdeci">_Tp height</div><div class="ttdoc">the height </div><div class="ttdef"><b>Definition:</b> types.hpp:340</div></div>
<div class="ttc" id="group__core__basic_html_ga346f563897249351a34549137c8532a0"><div class="ttname"><a href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">cv::Size</a></div><div class="ttdeci">Size2i Size</div><div class="ttdef"><b>Definition:</b> types.hpp:347</div></div>
<div class="ttc" id="dnn__superres_8hpp_html"><div class="ttname"><a href="../../d3/db0/dnn__superres_8hpp.html">dnn_superres.hpp</a></div></div>
<div class="ttc" id="group__core__basic_html_gaf20d857c2077c986d3b303e3d58bbc54"><div class="ttname"><a href="../../dc/d84/group__core__basic.html#gaf20d857c2077c986d3b303e3d58bbc54">cv::Vec2d</a></div><div class="ttdeci">Vec&lt; double, 2 &gt; Vec2d</div><div class="ttdef"><b>Definition:</b> matx.hpp:432</div></div>
<div class="ttc" id="group__imgproc__hal__functions_html_ga2fe39d2201b12e1b961ca56b2aff9ff2"><div class="ttname"><a href="../../d5/df1/group__imgproc__hal__functions.html#ga2fe39d2201b12e1b961ca56b2aff9ff2">cv::hal::resize</a></div><div class="ttdeci">void resize(int src_type, const uchar *src_data, size_t src_step, int src_width, int src_height, uchar *dst_data, size_t dst_step, int dst_width, int dst_height, double inv_scale_x, double inv_scale_y, int interpolation)</div></div>
<div class="ttc" id="group__imgproc__draw_html_ga5126f47f883d730f633d74f07456c576"><div class="ttname"><a href="../../d6/d6e/group__imgproc__draw.html#ga5126f47f883d730f633d74f07456c576">cv::putText</a></div><div class="ttdeci">void putText(InputOutputArray img, const String &amp;text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=LINE_8, bool bottomLeftOrigin=false)</div><div class="ttdoc">Draws a text string. </div></div>
<div class="ttc" id="group__imgproc__transform_html_gga5bb5a1fea74ea38e1a5445ca803ff121aa5521d8e080972c762467c45f3b70e6c"><div class="ttname"><a href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121aa5521d8e080972c762467c45f3b70e6c">cv::INTER_NEAREST</a></div><div class="ttdef"><b>Definition:</b> imgproc.hpp:247</div></div>
<div class="ttc" id="imgproc_2include_2opencv2_2imgproc_8hpp_html"><div class="ttname"><a href="../../d1/d4f/imgproc_2include_2opencv2_2imgproc_8hpp.html">imgproc.hpp</a></div></div>
<div class="ttc" id="group__core__basic_html_ga370d94209693b5b13437ab4991cabf73"><div class="ttname"><a href="../../dc/d84/group__core__basic.html#ga370d94209693b5b13437ab4991cabf73">cv::Vec3d</a></div><div class="ttdeci">Vec&lt; double, 3 &gt; Vec3d</div><div class="ttdef"><b>Definition:</b> matx.hpp:433</div></div>
<div class="ttc" id="classcv_1_1Scalar___html"><div class="ttname"><a href="../../d1/da0/classcv_1_1Scalar__.html">cv::Scalar_&lt; double &gt;</a></div></div>
<div class="ttc" id="classcv_1_1Mat_html"><div class="ttname"><a href="../../d3/d63/classcv_1_1Mat.html">cv::Mat</a></div><div class="ttdoc">n-dimensional dense array class </div><div class="ttdef"><b>Definition:</b> mat.hpp:801</div></div>
<div class="ttc" id="classcv_1_1Mat_html_abbec3525a852e77998aba034813fded4"><div class="ttname"><a href="../../d3/d63/classcv_1_1Mat.html#abbec3525a852e77998aba034813fded4">cv::Mat::empty</a></div><div class="ttdeci">bool empty() const</div><div class="ttdoc">Returns true if the array has no elements. </div></div>
<div class="ttc" id="group__core__basic_html_ga1e83eafb2d26b3c93f09e8338bcab192"><div class="ttname"><a href="../../dc/d84/group__core__basic.html#ga1e83eafb2d26b3c93f09e8338bcab192">cv::Point</a></div><div class="ttdeci">Point2i Point</div><div class="ttdef"><b>Definition:</b> types.hpp:194</div></div>
<div class="ttc" id="group__highgui_html_ga5628525ad33f52eab17feebcfba38bd7"><div class="ttname"><a href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">cv::waitKey</a></div><div class="ttdeci">int waitKey(int delay=0)</div><div class="ttdoc">Waits for a pressed key. </div></div>
</div><!-- fragment --><h2>Explanation </h2>
<ol type="1">
<li><p class="startli"><b>Read and downscale the image</b> </p><div class="fragment"><div class="line"><span class="keywordtype">int</span> width = img.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a> - (img.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a> % <a class="code" href="../../d6/d84/namespacecv_1_1quality_1_1quality__utils.html#ae55d1c89ff5761730174745401162743">scale</a>);</div><div class="line"><span class="keywordtype">int</span> height = img.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a> - (img.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a> % <a class="code" href="../../d6/d84/namespacecv_1_1quality_1_1quality__utils.html#ae55d1c89ff5761730174745401162743">scale</a>);</div><div class="line">Mat cropped = img(<a class="code" href="../../dc/d84/group__core__basic.html#ga11d95de507098e90bad732b9345402e8">Rect</a>(0, 0, width, height));</div><div class="line">Mat img_downscaled;</div><div class="line"><a class="code" href="../../da/d54/group__imgproc__transform.html#ga47a974309e9102f5f08231edc7e7529d">cv::resize</a>(cropped, img_downscaled, <a class="code" href="../../d6/d50/classcv_1_1Size__.html">cv::Size</a>(), 1.0 / scale, 1.0 / scale);</div></div><!-- fragment --><p class="startli">Resize the image by the scaling factor. Before that a cropping is necessary, so the images will align.</p>
</li>
<li><p class="startli"><b>Set the model</b> </p><div class="fragment"><div class="line">DnnSuperResImpl sr;</div><div class="line">sr.readModel(path);</div><div class="line">sr.setModel(algorithm, scale);</div><div class="line">sr.upsample(img_downscaled, img_new);</div></div><!-- fragment --><p class="startli">Instantiate a dnn super-resolution object. Read and set the algorithm and scaling factor.</p>
</li>
<li><p class="startli"><b>Perform benchmarking</b> </p><div class="fragment"><div class="line"><span class="keywordtype">double</span> psnr = <a class="code" href="../../d2/de8/group__core__array.html#ga3119e3ea73010a6f810bb05aa36ac8d6">PSNR</a>(img_new, cropped);</div><div class="line"><a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a> q = <a class="code" href="../../d9/db5/classcv_1_1quality_1_1QualitySSIM.html#a49d5ecc72e83b8876c8293244c3667e4">cv::quality::QualitySSIM::compute</a>(img_new, cropped, <a class="code" href="../../dc/d84/group__core__basic.html#gad9287b23bba2fed753b36ef561ae7346">cv::noArray</a>());</div><div class="line"><span class="keywordtype">double</span> ssim = <a class="code" href="../../d2/de8/group__core__array.html#ga191389f8a0e58180bb13a727782cd461">mean</a>(<a class="code" href="../../d6/dcf/classcv_1_1Vec.html">cv::Vec3f</a>(q[0], q[1], q[2]))[0];</div></div><!-- fragment --><p class="startli">Calculate PSNR and SSIM. Use OpenCVs PSNR (core opencv) and SSIM (contrib) functions to compare the images. Repeat it with other upscaling algorithms, such as other DL models or interpolation methods (eg. bicubic, nearest neighbor).</p>
</li>
</ol>
<h2>Benchmarking results </h2>
<h2>Dataset benchmarking </h2>
<h3>General100 dataset</h3>
<center></center><center><h5>2x scaling factor</h5>
</center><center></center><center><table class="doxtable">
<tr>
<th></th><th align="center">Avg inference time in sec (CPU)</th><th align="right">Avg PSNR </th><th align="right">Avg SSIM  </th></tr>
<tr>
<td>ESPCN </td><td align="center"><b>0.008795</b> </td><td align="right">32.7059 </td><td align="right">0.9276 </td></tr>
<tr>
<td>EDSR </td><td align="center">5.923450 </td><td align="right"><b>34.1300</b> </td><td align="right"><b>0.9447</b> </td></tr>
<tr>
<td>FSRCNN </td><td align="center">0.021741 </td><td align="right">32.8886 </td><td align="right">0.9301 </td></tr>
<tr>
<td>LapSRN </td><td align="center">0.114812 </td><td align="right">32.2681 </td><td align="right">0.9248 </td></tr>
<tr>
<td>Bicubic </td><td align="center">0.000208 </td><td align="right">32.1638 </td><td align="right">0.9305 </td></tr>
<tr>
<td>Nearest neighbor </td><td align="center">0.000114 </td><td align="right">29.1665 </td><td align="right">0.9049 </td></tr>
<tr>
<td>Lanczos </td><td align="center">0.001094 </td><td align="right">32.4687 </td><td align="right">0.9327 </td></tr>
</table>
<h5>3x scaling factor</h5>
</center><center></center><center><table class="doxtable">
<tr>
<th></th><th align="center">Avg inference time in sec (CPU)</th><th align="right">Avg PSNR </th><th align="right">Avg SSIM  </th></tr>
<tr>
<td>ESPCN </td><td align="center"><b>0.005495</b> </td><td align="right">28.4229 </td><td align="right">0.8474 </td></tr>
<tr>
<td>EDSR </td><td align="center">2.455510 </td><td align="right"><b>29.9828</b> </td><td align="right"><b>0.8801</b> </td></tr>
<tr>
<td>FSRCNN </td><td align="center">0.008807 </td><td align="right">28.3068 </td><td align="right">0.8429 </td></tr>
<tr>
<td>LapSRN </td><td align="center">0.282575 </td><td align="right">26.7330 </td><td align="right">0.8862 </td></tr>
<tr>
<td>Bicubic </td><td align="center">0.000311 </td><td align="right">26.0635 </td><td align="right">0.8754 </td></tr>
<tr>
<td>Nearest neighbor </td><td align="center">0.000148 </td><td align="right">23.5628 </td><td align="right">0.8174 </td></tr>
<tr>
<td>Lanczos </td><td align="center">0.001012 </td><td align="right">25.9115 </td><td align="right">0.8706 </td></tr>
</table>
</center><center><h5>4x scaling factor</h5>
</center><center></center><center><table class="doxtable">
<tr>
<th></th><th align="center">Avg inference time in sec (CPU)</th><th align="right">Avg PSNR </th><th align="right">Avg SSIM  </th></tr>
<tr>
<td>ESPCN </td><td align="center"><b>0.004311</b> </td><td align="right">26.6870 </td><td align="right">0.7891 </td></tr>
<tr>
<td>EDSR </td><td align="center">1.607570 </td><td align="right"><b>28.1552</b> </td><td align="right"><b>0.8317</b> </td></tr>
<tr>
<td>FSRCNN </td><td align="center">0.005302 </td><td align="right">26.6088 </td><td align="right">0.7863 </td></tr>
<tr>
<td>LapSRN </td><td align="center">0.121229 </td><td align="right">26.7383 </td><td align="right">0.7896 </td></tr>
<tr>
<td>Bicubic </td><td align="center">0.000311 </td><td align="right">26.0635 </td><td align="right">0.8754 </td></tr>
<tr>
<td>Nearest neighbor </td><td align="center">0.000148 </td><td align="right">23.5628 </td><td align="right">0.8174 </td></tr>
<tr>
<td>Lanczos </td><td align="center">0.001012 </td><td align="right">25.9115 </td><td align="right">0.8706 </td></tr>
</table>
</center><center></center><h2>Images </h2>
<center></center><center><h4>2x scaling factor</h4>
</center><center></center><center><table class="doxtable">
<tr>
<th align="center">Set5: butterfly.png </th><th align="center">size: 256x256 </th><th align="center"></th><th align="center"></th></tr>
<tr>
<td align="center"><div class="image">
<img src="../../orig_butterfly.jpg" alt="orig_butterfly.jpg"/>
<div class="caption">
Original</div></div>
</td><td align="center"><div class="image">
<img src="../../bicubic_butterfly.jpg" alt="bicubic_butterfly.jpg"/>
<div class="caption">
Bicubic interpolation</div></div>
</td><td align="center"><div class="image">
<img src="../../nearest_butterfly.jpg" alt="nearest_butterfly.jpg"/>
<div class="caption">
Nearest neighbor interpolation</div></div>
</td><td align="center"><div class="image">
<img src="../../lanczos_butterfly.jpg" alt="lanczos_butterfly.jpg"/>
<div class="caption">
Lanczos interpolation</div></div>
 </td></tr>
<tr>
<td align="center">PSRN / SSIM / Speed (CPU)</td><td align="center">26.6645 / 0.9048 / 0.000201 </td><td align="center">23.6854 / 0.8698 / <b>0.000075</b> </td><td align="center"><b>26.9476</b> / <b>0.9075</b> / 0.001039 </td></tr>
<tr>
<td align="center"><div class="image">
<img src="../../espcn_butterfly.jpg" alt="espcn_butterfly.jpg"/>
<div class="caption">
ESPCN</div></div>
</td><td align="center"><div class="image">
<img src="../../fsrcnn_butterfly.jpg" alt="fsrcnn_butterfly.jpg"/>
<div class="caption">
FSRCNN</div></div>
 </td><td align="center"><div class="image">
<img src="../../lapsrn_butterfly.jpg" alt="lapsrn_butterfly.jpg"/>
<div class="caption">
LapSRN</div></div>
 </td><td align="center"><div class="image">
<img src="../../edsr_butterfly.jpg" alt="edsr_butterfly.jpg"/>
<div class="caption">
EDSR</div></div>
</td></tr>
<tr>
<td align="center">29.0341 / 0.9354 / <b>0.004157</b></td><td align="center">29.0077 / 0.9345 / 0.006325 </td><td align="center">27.8212 / 0.9230 / 0.037937 </td><td align="center"><b>30.0347</b> / <b>0.9453</b> / 2.077280 </td></tr>
</table>
<h4>3x scaling factor</h4>
</center><center></center><center><table class="doxtable">
<tr>
<th align="center">Urban100: img_001.png </th><th align="center">size: 1024x644 </th><th align="center"></th><th align="center"></th></tr>
<tr>
<td align="center"><div class="image">
<img src="../../orig_urban.jpg" alt="orig_urban.jpg"/>
<div class="caption">
Original</div></div>
</td><td align="center"><div class="image">
<img src="../../bicubic_urban.jpg" alt="bicubic_urban.jpg"/>
<div class="caption">
Bicubic interpolation</div></div>
</td><td align="center"><div class="image">
<img src="../../nearest_urban.jpg" alt="nearest_urban.jpg"/>
<div class="caption">
Nearest neighbor interpolation</div></div>
</td><td align="center"><div class="image">
<img src="../../lanczos_urban.jpg" alt="lanczos_urban.jpg"/>
<div class="caption">
Lanczos interpolation</div></div>
 </td></tr>
<tr>
<td align="center">PSRN / SSIM / Speed (CPU)</td><td align="center">27.0474 / <b>0.8484</b> / 0.000391 </td><td align="center">26.0842 / 0.8353 / <b>0.000236</b> </td><td align="center"><b>27.0704</b> / 0.8483 / 0.002234 </td></tr>
<tr>
<td align="center"><div class="image">
<img src="../../espcn_urban.jpg" alt="espcn_urban.jpg"/>
<div class="caption">
ESPCN</div></div>
</td><td align="center"><div class="image">
<img src="../../fsrcnn_urban.jpg" alt="fsrcnn_urban.jpg"/>
<div class="caption">
FSRCNN</div></div>
 </td><td align="center">LapSRN is not trained for 3x <br />
 because of its architecture </td><td align="center"><div class="image">
<img src="../../edsr_urban.jpg" alt="edsr_urban.jpg"/>
<div class="caption">
EDSR</div></div>
</td></tr>
<tr>
<td align="center">28.0118 / 0.8588 / <b>0.030748</b></td><td align="center">28.0184 / 0.8597 / 0.094173 </td><td align="center"></td><td align="center"><b>30.5671</b> / <b>0.9019</b> / 9.517580 </td></tr>
</table>
</center><center><h4>4x scaling factor</h4>
</center><center></center><center><table class="doxtable">
<tr>
<th align="center">Set14: comic.png </th><th align="center">size: 250x361 </th><th align="center"></th><th align="center"></th></tr>
<tr>
<td align="center"><div class="image">
<img src="../../orig_comic.jpg" alt="orig_comic.jpg"/>
<div class="caption">
Original</div></div>
</td><td align="center"><div class="image">
<img src="../../bicubic_comic.jpg" alt="bicubic_comic.jpg"/>
<div class="caption">
Bicubic interpolation</div></div>
</td><td align="center"><div class="image">
<img src="../../nearest_comic.jpg" alt="nearest_comic.jpg"/>
<div class="caption">
Nearest neighbor interpolation</div></div>
</td><td align="center"><div class="image">
<img src="../../lanczos_comic.jpg" alt="lanczos_comic.jpg"/>
<div class="caption">
Lanczos interpolation</div></div>
 </td></tr>
<tr>
<td align="center">PSRN / SSIM / Speed (CPU)</td><td align="center"><b>19.6766</b> / <b>0.6413</b> / 0.000262 </td><td align="center">18.5106 / 0.5879 / <b>0.000085</b> </td><td align="center">19.4948 / 0.6317 / 0.001098 </td></tr>
<tr>
<td align="center"><div class="image">
<img src="../../espcn_comic.jpg" alt="espcn_comic.jpg"/>
<div class="caption">
ESPCN</div></div>
</td><td align="center"><div class="image">
<img src="../../fsrcnn_comic.jpg" alt="fsrcnn_comic.jpg"/>
<div class="caption">
FSRCNN</div></div>
 </td><td align="center"><div class="image">
<img src="../../lapsrn_comic.jpg" alt="lapsrn_comic.jpg"/>
<div class="caption">
LapSRN</div></div>
 </td><td align="center"><div class="image">
<img src="../../edsr_comic.jpg" alt="edsr_comic.jpg"/>
<div class="caption">
EDSR</div></div>
</td></tr>
<tr>
<td align="center">20.0417 / 0.6302 / <b>0.001894</b></td><td align="center">20.0885 / 0.6384 / 0.002103 </td><td align="center">20.0676 / 0.6339 / 0.061640 </td><td align="center"><b>20.5233</b> / <b>0.6901</b> / 0.665876 </td></tr>
</table>
<h4>8x scaling factor</h4>
</center><center></center><center><table class="doxtable">
<tr>
<th align="center">Div2K: 0006.png </th><th align="center">size: 1356x2040 </th><th align="center"></th></tr>
<tr>
<td align="center"><div class="image">
<img src="../../orig_div2k.jpg" alt="orig_div2k.jpg"/>
<div class="caption">
Original</div></div>
</td><td align="center"><div class="image">
<img src="../../bicubic_div2k.jpg" alt="bicubic_div2k.jpg"/>
<div class="caption">
Bicubic interpolation</div></div>
</td><td align="center"><div class="image">
<img src="../../nearest_div2k.jpg" alt="nearest_div2k.jpg"/>
<div class="caption">
Nearest neighbor interpolation</div></div>
</td></tr>
<tr>
<td align="center">PSRN / SSIM / Speed (CPU)</td><td align="center">26.3139 / <b>0.8033</b> / 0.001107</td><td align="center">23.8291 / 0.7340 / <b>0.000611</b> </td></tr>
<tr>
<td align="center"><div class="image">
<img src="../../lanczos_div2k.jpg" alt="lanczos_div2k.jpg"/>
<div class="caption">
Lanczos interpolation</div></div>
</td><td align="center"><div class="image">
<img src="../../lapsrn_div2k.jpg" alt="lapsrn_div2k.jpg"/>
<div class="caption">
LapSRN</div></div>
 </td><td align="center"></td></tr>
<tr>
<td align="center">26.1565 / 0.7962 / 0.004782</td><td align="center"><b>26.7046</b> / 0.7987 / 2.274290 </td><td align="center"></td></tr>
</table>
</center> </div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:38 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
